function showform(data,postid,parentid) {
	$("#CommentForm"+postid+"-"+parentid).html(data);
	$("#CommentForm"+postid+"-"+parentid).slideToggle('slow', function() {$("#CommentForm"+postid+"-"+parentid+" #CommentText").focus();} );


	$("input#a"+postid+"-"+parentid).click(function() {
		$("#CommentForm"+postid+"-"+parentid).slideToggle('slow');
		$("#CommentForm"+postid+"-"+parentid).html("");
		return false;
	});

    $("#cForm"+postid+"-"+parentid).submit( function() {
		return $("textarea",this).val().length > 3;
	});

}

function showvote(data,comid) {
	$("#vote"+comid).html(data);
}

function showbookmark(data,postid) {
	$("#b"+postid).html(data);
}

function bookmark(postid,act) {
if (act==1)
	act="add";
if (act==0)
	act="delete";

$.ajax({ type: "GET", url: "/bookmarks/"+act+"/"+postid+"/"+"?rnd="+ Math.random(), success: function(data){showbookmark(data,postid); } });
}

function form() {
this.blur();
var link=this.href.match(/\d+/g);
var postid=link[0];
var parentid=link[1];
$.ajax({ type: "GET", url: "/comments/form/"+postid+"/"+parentid+"/"+"?rnd="+ Math.random(), success: function(data){showform(data,postid,parentid); } });
return false;
}

function vote(comid,v) {
var link=this.href.match(/\d+/g);
var comid=link[0];
var v=link[1];
if(v>0) v=1; else v=0;
$.ajax({ type: "GET", url: "/votes/add/"+comid+"/"+v+"/"+"?rnd="+ Math.random(), success: function(data){showvote(data,comid); } });
return false;
}

$(function(){
$('h2.i-comm a, a.replink').bind('click', form);
$('a.vplus, a.vminus').bind('click', vote);
});